package com.mes.basicdata.domain;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.OrderBy;
import org.springframework.context.annotation.Lazy;

import com.mes.common.domain.BasicModel;

/*import org.codehaus.xfire.aegis.type.java5.XmlType;

import com.mes.common.model.BasicModel;*/

/**
 * <p>
 * 工艺变更对象
 * 
 * 
 */

@Entity()
@Table(name = "B_ECO_HEADER")
@BatchSize(size=20)
@Lazy(value=true)
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class EngineeringChange extends BasicModel implements
		java.io.Serializable {

	public final static int ECO_WIPSTATE_DRAFT = 0; // 草案
	public final static int ECO_WIPSTATE_WAITING = 1; // 等待变更中
	public final static int ECO_WIPSTATE_COMPLETED = 2; // 正常工序
	public final static int ECO_MANHOURSTATE_DRAFT = 0; // 草案
	public final static int ECO_MANHOURSTATE_WAITING = 1; // 等待变更中
	public final static int ECO_MANHOURSTATE_COMPLETED = 2; // 已变更
	public final static int ECO_STATE_DRAFT = 0; // 草案
	public final static int ECO_STATE_SUBMITED = 1; // 草案
	public final static int ECO_STATE_PASSED = 2; // 草案
	public final static int ECO_STATE_COMPLETED = 3; // 已变更
	public final static int ECO_STATE_CANCELED = 4; // 已取消
	
	@Id
	@GenericGenerator(name = "changeUid", strategy = "assigned")
	@Column(name="CHANGEUID",unique=true)
	private String changeUid;
	
	// 变更单号
	@Column(name="CHANGEID")
	private String changeId;
	
	// 变更类型
	@Column(name="ECOTYPE")
	private String ecoType;
	
	//对应的变更前物料
	@Column(name="PART_NUMBER")
	private String fromPartUid;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="PART_NUMBER",insertable=false,updatable=false)
	private Part fromPart;
	
	// 变更前的工艺
	@Column(name="FROMROUTING")
	private String fromRoutingUid;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="FROMROUTING",insertable=false,updatable=false)
	private Routing fromRouting;
	
	//对应的变更后物料
	@Column(name="TO_PART_NUMBER")
	private String toPartUid;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="PART_NUMBER",insertable=false,updatable=false)
	private Part toPart;
	
	// 变更后的工艺
	@Column(name="TOROUTING")
	private String toRoutingUid;
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="TOROUTING",insertable=false,updatable=false)
	private Routing toRouting;
	
	// 审核者
	@Column(name="APPROVER")
	private Employee approver;
	
	// 审核时间
	@Column(name="APPROVETIME")
	private Date approveTime;
	
	// 变更单状态
	@Column(name="ECOSTATE")
	private Long ecoState;
	
	// 是否影响在制品
	@Column(name="WIPSTATE")
	private Long wipState;
	
	//所影响的在制品批次
	@Column(name="WIPBATCHS")
	private String wipBatchs;
	
	// 是否影响工时
	@Column(name="MANHOURSTATE")
	private Long manHourState;
	
//	private String fromRoutingOutUid;
//	private String toRoutingOutUid;
	
	@OneToMany(fetch=FetchType.LAZY, mappedBy = "engineeringChange")
	@OrderBy(clause="SEQ asc")
	private Set<EngineeringChangeDetail> ecoDetails;

	
	/** default constructor */
	public EngineeringChange() {
	}

	@Override
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.getChangeUid();
	}
	@Override
	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.setChangeUid(uuid);
	}
	
	public String getChangeUid() {
		return changeUid;
	}


	public void setChangeUid(String changeUid) {
		this.changeUid = changeUid;
	}


	public String getChangeId() {
		return changeId;
	}


	public void setChangeId(String changeId) {
		this.changeId = changeId;
	}


	public String getEcoType() {
		return ecoType;
	}


	public void setEcoType(String ecoType) {
		this.ecoType = ecoType;
	}


	public String getFromPartUid() {
		return fromPartUid;
	}


	public void setFromPartUid(String fromPartUid) {
		this.fromPartUid = fromPartUid;
	}


	public Part getFromPart() {
		return fromPart;
	}


	public void setFromPart(Part fromPart) {
		this.fromPart = fromPart;
	}


	public String getFromRoutingUid() {
		return fromRoutingUid;
	}


	public void setFromRoutingUid(String fromRoutingUid) {
		this.fromRoutingUid = fromRoutingUid;
	}


	public Routing getFromRouting() {
		return fromRouting;
	}


	public void setFromRouting(Routing fromRouting) {
		this.fromRouting = fromRouting;
	}


	public String getToPartUid() {
		return toPartUid;
	}


	public void setToPartUid(String toPartUid) {
		this.toPartUid = toPartUid;
	}


	public Part getToPart() {
		return toPart;
	}


	public void setToPart(Part toPart) {
		this.toPart = toPart;
	}


	public String getToRoutingUid() {
		return toRoutingUid;
	}


	public void setToRoutingUid(String toRoutingUid) {
		this.toRoutingUid = toRoutingUid;
	}


	public Routing getToRouting() {
		return toRouting;
	}


	public void setToRouting(Routing toRouting) {
		this.toRouting = toRouting;
	}


	public Employee getApprover() {
		return approver;
	}


	public void setApprover(Employee approver) {
		this.approver = approver;
	}


	public Date getApproveTime() {
		return approveTime;
	}


	public void setApproveTime(Date approveTime) {
		this.approveTime = approveTime;
	}


	public Long getEcoState() {
		return ecoState;
	}


	public void setEcoState(Long ecoState) {
		this.ecoState = ecoState;
	}


	public Long getWipState() {
		return wipState;
	}


	public void setWipState(Long wipState) {
		this.wipState = wipState;
	}


	public String getWipBatchs() {
		return wipBatchs;
	}


	public void setWipBatchs(String wipBatchs) {
		this.wipBatchs = wipBatchs;
	}


	public Long getManHourState() {
		return manHourState;
	}


	public void setManHourState(Long manHourState) {
		this.manHourState = manHourState;
	}


	public Set<EngineeringChangeDetail> getEcoDetails() {
		return ecoDetails;
	}


	public void setEcoDetails(Set<EngineeringChangeDetail> ecoDetails) {
		this.ecoDetails = ecoDetails;
	}

	

}